<?php
include('/var/www/html/new/d/module/api/function.class.php');
$Inside= new SoapClient(null,array(
        "location" => "http://localhost/open/openService/pft_insideMX.php",
        "uri" => "www.16u.com?ac_16u=16ucom|pw_16u=c33367701511b4f6020ec61ded352059|auth_16u=true")
);
if (!class_exists("go_sql")){
	include("/var/www/html/new/conf/le.je"); 
	$le=new go_sql();
	$le->connect();
}

$txt1 = $_REQUEST['json'];
// $txt1 = 'Y2hlY2sjNDQ4MmFlM2E0NDAyNjE3MjQwMjNiMDMxOWY3NjFkZTV8W3sicmVhbEFtb3VudCI6MC4w
// LCJhY2NvdW50IjoiMTIzOTUwIiwiYW1vdW50IjowLjAsInBlcnNvbkNvdW50IjoyLCJvcmRlcklk
// IjoiMjI2NTQ5NSIsInVwZGF0ZVRpbWUiOiIyMDE1LTA5LTE3IDE1OjU2OjM2IiwicXJDb2RlIjpu
// dWxsLCJzeW5jaCI6ZmFsc2UsInJlYWxQZXJzb25Db3VudCI6Mn1d';
// exit;
$arr = base64_decode($txt1);
logfile(date('Y-m-d H:i:s').'|'.$arr);
$arrs1 = explode('#',$arr);
$arrs2 = explode('|',$arrs1[1]);
$method = $arrs1[0];
$Check = $arrs2[0];
$order_arr = json_decode($arrs2[1],true);
$order_arr_id = $order_arr[0]['orderId'];
$updateTime = $order_arr[0]['updateTime'];
$sign = md5($order_arr_id.$method); 

if($Check == $sign){
	$order_arr = $order_arr[0];
	$orderid = $order_arr['orderId'];
	$pft_order = $Inside->Order_Globle_Search(
		0,0,0,0,"",
		"","","","","",
		"","",$orderid,"",0,
		"","","",1,0,
		0,1,0,"","",
		"","","","","",
		"","","","",""
	);
	if(strlen($pft_order)>50){
		$PFT_infunction = new AllFunction();
		$pft_order_xml = simplexml_load_string($pft_order);
		$UUaids = (string)$pft_order_xml->Rec->UUaids;
		if($UUaids == 0){
			$aid = (string)$pft_order_xml->Rec->UUsellid;
		}else{
			$UUaidss= explode(',',$UUaids);
			$aid = $UUaidss[0];
		}
		$select_account ='select account from pft_member where id='.$aid." limit 1"; 
		$GLOBALS['le']->query($select_account);
		$account1= $GLOBALS['le']->fetch_assoc(); 
		$account=$account1['account'];
		if($order_arr['account']!= $account){
			$repCode = 106;
			response($repCode,"|无授权，拒绝连接");
			exit;
		}
		if((string)$pft_order_xml->Rec->UUp_type == 'F'){ //查套票子票订单
			if($method == 'modifycheck' && $order_arr['realPersonCount']!=0){
				$totalprice=(string)$pft_order_xml->Rec->UUtprice*$order_arr['realPersonCount'];
				$modify_order=$Inside->Order_Change_Pro(
				$orderid,$order_arr['realPersonCount'],$totalprice,0,0);
				logfile($modify_order."|".$orderid);
				if($modify_order !=141 && $modify_order !=100 ){ 
					$repCode = 107;
					response($repCode,"|部分订单修改失败");
					exit;
				}
			}
			if($method == 'check' || $modify_order == 141 || $modify_order==100 ){			
				$xmlChildOrders = $Inside->Order_Globle_Search(
							"","","","","",
							"","","","","",
							"","",$orderid,"","",
							"","","",1,1,
							0,999,"","","",
							"","","","","",
							"",0,2
						);
				$simxml2 = simplexml_load_string($xmlChildOrders);
				foreach($simxml2 as $r2) {
					$UUsalerid = (string)$r2->UUsalerid;
					$UUordernum = (string)$r2->UUordernum;
					$UUcode = (string)$r2->UUcode;
					$chkIns = 499;
					if((string)$r2->UUstatus==2) $chkIns = 498;
					$yz = $PFT_infunction->Unified_Check_IN($UUsalerid,$UUcode,$updateTime,$chkIns);
					if($yz == 100 || $yz == 293){
						$repCode = 100;
						response($repCode,$orderid."|".$UUordernum."|验证成功");
					}
					else{
						$repCode = $yz;
						response($repCode,$orderid."|".$UUordernum."|验证失败");
					}
				}
			}
			else{
				$repCode = 102;
				response($repCode,"|方法名错误");
				exit;
			}
		}
		else{
			$repCode = 103;
			response($repCode,"|非套票订单");
			exit;
		}
	}
	else{
		$repCode = 104;
		response($repCode,"|未找到订单");
		exit;
	}
}
else{
	$repCode = 1041;
	response($repCode,"|验证不通过");
	exit;
}

function Err_Word($r){
	$errCode = array(
		'105'=>'找不到订单',
		'121'=>'订单状态出错,订单已验证',
		'119'=>'订单状态出错,已取消或其他状态',
		'521'=>'验证间隔时间未到',
		'133'=>'游玩时间未到',
		'134'=>'游玩时间已过',
		'118'=>'终端服务器无响应',
		'1070'=>'订单未支付',
	);
	$eword=$errCode[$r];
	if (!$eword) $eword='其他错误';
	return $eword;
}

function logfile($word){
	$filepath= '/var/www/html/new/d/logs/api/yunding_check/jt_log.txt';
	$word = date("Y-m-d H:i:s")."|".$word;
	if(file_exists($filepath)){
		$maxsize  = 1024*1024*10;
		$filesize = filesize($filepath);
		$filetype = end(explode(".",$filepath));
		$filename = substr($filepath,0,strpos($filepath,'.'));
		if($filesize>$maxsize)
			rename($filepath, $filename.'_'.date('YmdHis').'.'.$filetype);
	}
	$fp = fopen($filepath,"a");
	flock($fp, LOCK_EX);
	fwrite($fp,$word."\n");
	flock($fp, LOCK_UN);
	fclose($fp);
}

function response($repCode,$txt){
	logfile($repCode.$txt);
	echo $repCode;
}
/*
100 验证成功
101 验证失败
102	方法名错误
103	非套票订单
104 未找到订单
1041 验证不通过
106 无授权，拒绝连接
107 部分订单修改失败
*/
?>